package top.jiangqiang.crawler.core.http.entities.body;

import lombok.Getter;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.xml.XmlUtil;
import org.jetbrains.annotations.NotNull;
import top.jiangqiang.crawler.core.http.constants.ContentType;

import java.util.HashMap;
import java.util.Map;

@Getter
public class XmlBody extends RawStringBody {
    private final String contentType = ContentType.XML.getValue();

    @NotNull
    @Override
    @SuppressWarnings("all")
    public Map<String, Object> getData() {
        String bodyStr = getBodyStr();
        if (StrUtil.isBlank(bodyStr)) {
            return new HashMap<>();
        } else {
            return XmlUtil.xmlToMap(bodyStr);
        }
    }
}
